package com.wzcl.app.model.vo;

import com.wzcl.app.dao.model.Cart;
import com.wzcl.app.dao.model.Course;
import com.wzcl.app.model.common.WZCL;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.springframework.beans.BeanUtils;

import java.util.Map;

@EqualsAndHashCode(callSuper = false)
@Data
public class CartVo extends BaseVo {
    private static final long serialVersionUID = 1L;


    @ApiModelProperty(value = "用户")
    private Integer userId;
    private String userPhone;

    @ApiModelProperty(value = "商品")
    private CommodityVo commodity;

    @ApiModelProperty("课程")
    private Course course;

    @ApiModelProperty(value = "状态")
    private Integer state;
    private String stateStr;

    private CartVo() {
    }

    public static CartVo create(Cart cart){
        CartVo cartVo = new CartVo();
        BeanUtils.copyProperties(cart,cartVo,"commodity");
        cartVo.translationValueStr();
        if(cart.getCommodity() != null){
            cartVo.commodity = CommodityVo.create(cart.getCommodity());
        }
        return cartVo;
    }

    @Override
    public void translationValueStr() {
        Map<String, Map<Integer, String>> map = getTranslationMap();
        this.stateStr = map.get(WZCL.GROUP_NAME.STATE).get(this.state);
    }

    @Override
    public void processResources() {

    }
}
